package cn.swust.designpatternlearningplatform.dao.sql;

import cn.swust.designpatternlearningplatform.domain.entity.PaperResult;
import org.apache.ibatis.jdbc.SQL;

public class PaperResultDaoSql {
    /**
     * @param paperResult1:
     * @return String
     * @author wang
     * description 将做题数据上传到结果类里面
     * date 2023/5/9 20:25
     */
    public String insertPaperResult(PaperResult paperResult1) {
        String paperNumber = paperResult1.getPaperNumber();
        Integer topicId = paperResult1.getTopicId();
        String studentNumber = paperResult1.getStudentNumber();
        String ownAnswer = paperResult1.getOwnAnswer();
        Integer isRight = paperResult1.getIsRight();
        return new SQL() {
            {
                INSERT_INTO("paper_result");
                VALUES("paper_number", "#{paperNumber}");
                VALUES("topic_id", "#{topicId}");
                VALUES("student_number", "#{studentNumber}");
                VALUES("own_answer", "#{ownAnswer}");
                VALUES("is_right", "#{isRight}");
            }
        }.toString();
    }

    /**
     * @param studentNumber:
     * @param paperNumber:
     * @return String
     * @author wang
     * description 通过学号以及试卷号获取答题情况
     * date 2023/5/19 13:45
     */
    public String getPaperResult(String studentNumber, String paperNumber) {
        return new SQL() {
            {
                SELECT("*");
                FROM("paper_result");
                WHERE("student_number=#{studentNumber}", "paper_number=#{paperNumber}");
            }
        }.toString();
    }

    /**
     * @param testId:
     * @return String
     * @author wang
     * description 通过试卷号查询改试卷的所有学生的成绩
     * date 2023/5/19 17:13
     */
    public String getPaperResultByTestId(String testId) {
        return new SQL() {
            {
                SELECT("*");
                FROM("paper_result");
                WHERE("paper_number=#{testId}");
            }
        }.toString();
    }

    /**
     * @param testId:
     * @return String
     * @author wang
     * description 删除对应的答案
     * date 2023/5/25 0:38
     */
    public String deleteResult(String testId) {
        return new SQL() {
            {
                DELETE_FROM("paper_result");
                WHERE("paper_number=#{testId}");
            }
        }.toString();
    }

    /**
     * @param testId:
     * @return String
     * @author wang
     * description 通过试卷id来查找做过这套试卷的学生的学号，用于查找试卷结果
     * date 2023/6/1 16:16
     */
    public String getStudentNumber(String testId) {
        return new SQL() {
            {
                SELECT("student_number");
                FROM("paper_result");
                WHERE("paper_number=#{testId}");
            }
        }.toString();
    }

    /**
     * @param testId:
     * @param studentNumber:
     * @return String
     * @author wang
     * description
     * date 2023/6/1 17:49
     */
    public String getTopicId(String testId, String studentNumber) {
        return new SQL() {
            {
                SELECT("topic_id");
                FROM("paper_result");
                WHERE("paper_number=#{testId}", "student_number=#{studentNumber}");
            }
        }.toString();
    }

}
